{% extends 'layout.html' %}
{% load my_tags %}
{% block content %}

    <h4>NGINX管理</h4>

    <div class="row" style="margin-top: 20px; margin-bottom: 20px">
        <div class="col-md-7">
            {#            {% if per.add %}#}
            {#                <button style="margin-right: 60px" href="#"  class="btn btn-primary" id="ingress_build">批量创建</button>#}
            {#            {% endif %}#}
        </div><!-- /.col-lg-6 -->

        <div class="col-md-5">
            <form>
                <div class="input-group">
                    <select type="text" class="form-control" name="group" id="current_group">
                        {% for gg in groups %}
                            {% if gg.0 == group %}
                                <option value="{{ gg.0 }}" selected="selected">{{ gg.1 }}</option>
                            {% else %}
                                <option value="{{ gg.0 }}">{{ gg.1 }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                    <select type="text" class="form-control" name="env" id="current_env">
                        {% for ev in envs %}
                            {% if env == ev.0 %}
                                <option value="{{ ev.0 }}" selected="selected">{{ ev.1 }}</option>
                            {% else %}
                                <option value="{{ ev.0 }}">{{ ev.1 }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                    {% if appname %}
                        <input type="text" class="form-control" name="appname" value="{{ appname }}">
                    {% else %}
                        <input type="text" id="current_app" class="form-control" name="appname" placeholder="搜索">
                    {% endif %}

                    <span class="input-group-btn">
                    <button class="btn btn-info" type="submit">搜索</button>
                  </span>
                </div><!-- /input-group -->
            </form>
        </div><!-- /.col-lg-6 -->
    </div><!-- /.row -->

    <div class="modal fade" id="ingress_info" tabindex="-1" role="dialog">
        <div class="modal-dialog  modal-mg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">编辑应用信息</h4>
                    <button type="button" class="close" data-dismiss="modal" data-target="bs-example-modal-lg"
                            aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group" style="display: none">
                            <label for="proj_iddd" class="control-label">ID:</label>
                            <input type="text" class="form-control" id="proj_iddd" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="domain_addr">域名(必填，多个换行分割):</label>
                            <textarea class="form-control" id="domain_addr" rows="2" placeholder="域名"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="app_port" class="control-label">应用端口(http):</label>
                            <input type="text" class="form-control" id="app_port" placeholder="端口">
                        </div>
                        <div class="form-group">
                            <label for="request_path" class="control-label">请求路径:</label>
                            <input type="text" class="form-control" id="request_path" placeholder="请求路径">
                        </div>
                        <div class="form-group">
                            <label for="service_path" class="control-label">应用路径(为空时，默认=请求路径):</label>
                            <input type="text" class="form-control" id="service_path" placeholder="应用路径">
                        </div>
                        <div class="form-group">
                            <label class="form-check-label">
												<input class="form-check-input" type="checkbox" value="" id="personalize_edit">
												<span class="form-check-sign">自定义设置</span>
											</label>
                        </div>
                        <div class="form-group" style="display: none" id="personalize_eed">
                            <label for="personalize">自定义内容(必填，以分号(";")结尾，多个换行分割):</label>
                            <textarea class="form-control" id="personalize" rows="2" placeholder="自定义内容"></textarea>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="close_ip">关闭</button>
                    <button type="button" class="btn btn-primary" search-app="{{ search_app }}" id="save_http_app">保存
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <div class="modal fade" id="select_info" tabindex="-1" role="dialog">
        <div class="modal-dialog  modal-mg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">查看应用信息</h4>
                    <button type="button" class="close" data-dismiss="modal" data-target="bs-example-modal-lg"
                            aria-label="Close"><span aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group" style="display: none">
                            <label for="proj_iddds" class="control-label">ID:</label>
                            <input type="text" class="form-control" id="proj_iddds" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="domain_addrs">域名(必填，多个换行分割):</label>
                            <textarea class="form-control" id="domain_addrs" rows="2" placeholder="域名" readonly="readonly"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="app_ports" class="control-label">应用端口(http):</label>
                            <input type="text" class="form-control" id="app_ports" placeholder="端口" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="request_paths" class="control-label">请求路径:</label>
                            <input type="text" class="form-control" id="request_paths" placeholder="请求路径" value="/" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label for="service_paths" class="control-label">应用路径(为空时，默认=请求路径):</label>
                            <input type="text" class="form-control" id="service_paths" placeholder="应用路径" readonly="readonly">
                        </div>
                        <div class="form-group">
                            <label class="form-check-label">
												<input class="form-check-input" type="checkbox" value="" id="personalize_select" disabled="disabled">
												<span class="form-check-sign">自定义设置</span>
											</label>
                        </div>
                        <div class="form-group" style="display: none" id="personalize_ses">
                            <label for="personalizess">自定义内容(必填，以;结尾，多个换行分割):</label>
                            <textarea class="form-control" id="personalizess" rows="2" placeholder="自定义内容" readonly="readonly"></textarea>
                        </div>

                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" id="close_ip">关闭</button>
                    </button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <table class="table table-bordered table-striped">
        <thead>
        <tr>
            <th>选择</th>
            <th>应用名称</th>
            <th>组</th>
            <th>环境</th>
            <th>访问路径</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for service in server_list %}
            <tr>
                <td><label class="form-check-label">
                    <input class="form-check-input" type="checkbox" data-appss-id="{{ service.id }}"
                           data-app-idss="application-app" value="">
                    <span class="form-check-sign"></span>
                </label></td>
                <td>{{ service.sername.sername }}</td>
                <td>{{ service.group.name }}</td>
                <td>{{ service.get_env_type_display }}</td>
                {% if service.hostname %}
                    {% ingress_deal service.hostname service.request_path%}
                {% else %}
                    <td></td>
                {% endif %}
                <td>
                    {% if service.ingress_type == 1 %}
                        <button class="btn btn-success">{{ service.get_ingress_type_display }}</button>
                    {% elif service.ingress_type == 2 %}
                        <button class="btn btn-warning ingress_create" data-proj-id="{{ service.id }}">{{ service.get_ingress_type_display }}</button>
                    {% else %}
                        <button class="btn btn-default ingress_create" data-proj-id="{{ service.id }}">{{ service.get_ingress_type_display }}</button>
                    {% endif %}
                </td>
            {% if service.ingress_type == 1 %}
                <td>
                    {% if per.edit %}
                        <a href="#" class="btn btn-default selectproj" data-proj-id="{{ service.id }}"
                           data-env-id="{{ service.env_type }}">查看</a>
                    {% endif %}
                    {% if per.delete %}
                        <a href="#" class="btn btn-danger updateproj" data-proj-id="{{ service.id }}"
                           data-proj-name="{{ service.sername.sername }}">重置</a>
                    {% endif %}
                </td>
            {% else %}
                <td>
                    {% if per.edit %}
                        <a href="#" class="btn btn-warning editproj" data-proj-id="{{ service.id }}"
                           data-env-id="{{ service.env_type }}">编辑</a>
                    {% endif %}
                </td>
            {% endif %}
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <ul class="pagination pg-primary pull-right">
        {{ page_html|safe }}
    </ul>

{% endblock %}

{% block jss %}
    <script src="/static/httpservice/httpservicelist.js"></script>
{% endblock %}